// JavaScript Document

//debug function for testing purposes
function debug(msg){
		debugwindow=window.open('','debug','toolbar=1,resizable=1,width=500,height=500,scrollbars=yes');
		debugwindow.document.writeln(msg+'<br>');
	}
	
function doUrl(tabID,search){
debug("doUrl");
window.top.location=_args()["parent"]+"/Application.aspx?appId="+apid+"&up_chk=1&up_tab="+tabID;

}

function chngTab(tabId){
	
}

function changeLang(tid){
debug("changeLang");

url="http://orkut.familybuilder.com/changeLanguage.php?profile_id="+tid+"&langid="+document.getElementById('languageSettings').value;

			var params = {};


			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
makeCachedRequest(url, function(responseText){

window.top.location=_args()["parent"]+"/Application.aspx?appId=87222226184&up_chk=1&up_tab=tl_0_6";


}, params,0) ;

}

function changeLanguage(val){
	debug("changeLanguage");
document.getElementById("languageSettings").value=val;

}

function doRequest(tabId) {
	debug("doRequest");
//alert('doreqst');

var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');

//simer code

var opt_params = { };
opt_params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [opensocial.Person.Field.PROFILE_URL];

req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER, opt_params), "viewer");
req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS, opt_params), "viewer_friends");

req.add(req.newFetchActivitiesRequest(opensocial.DataRequest.Group.OWNER_FRIENDS, opt_params), "viewer_activities");
req.send(response);


//simer code



req.add(req.newFetchPersonAppDataRequest('VIEWER', ['LastPoked']), 'viewerData');

req.send(function(data){

person = data.get('viewer').getData();

my_data = data.get('viewerData');



my_data = my_data.getData() || {};

//console.log("renderPerson", person.getDisplayName(), person);
var profile_nameO = person.getField(opensocial.Person.Field.NAME);
var profile_pic = person.getField(opensocial.Person.Field.THUMBNAIL_URL);
var profile_name = person.getDisplayName();
var profile_id=person.getId();
var profile_Re='';//person.getAppField(field);
var profile_email=person.getField(opensocial.Person.Field.EMAIL);
var profile_url=person.getField(opensocial.Person.Field.PROFILE_URL);
var profile_gender=person.getField(opensocial.Enum.GENDER);

//var profile_gender=person.getField(opensocial.Person.Field.GENDER).getValue();
//alert(profile_gender);

if (profile_pic == "null" || profile_pic == "") {
profile_pic = server_url + "/img/i_nophoto64.gif";
}

apid=87222226184;
var ck=readCookie('gu'+profile_id); 
if(ck=="b")
{
var cook=1;
}
else
{
var cook=0;
}
stringuri="cook="+cook+"&profile_nameO="+escape(profile_nameO)+"&profile_pic="+escape(profile_pic)+"&profile_name="+escape(profile_name)+"&profile_id="+escape(profile_id)+"&profile_Re="+escape(profile_Re)+"&profile_email="+escape(profile_email)+"&apid="+escape(apid)+"&purl="+escape(profile_url)+"&pgender="+escape(profile_gender);
arrName=profile_name.split(' ');
var date = new Date();

var vlang=document.getElementById('langV').value;
//alert(vlang);
var ck=readCookie('gu'+profile_id); 
//alert(ck);
if(ck && ck!="" && ck!="g")
{
switch (ck){
			case 'a':
			if(vlang==0)
			{
			document.getElementById('addiv').innerHTML="<img src='http://orkut.familybuilder.com/images/header_images/steps1.gif' align='center'>"; 	
			
			}
			else
			{
			document.getElementById('addiv').innerHTML="<img src='http://orkut.familybuilder.com/spanish_images/steps1.gif' align='center'>";
			}
			url="http://orkut.familybuilder.com/intialsetup_new.php?"+stringuri;

		var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
    makeCachedRequest(url, function(responseText){
    document.getElementById('output').innerHTML=responseText.text;
    gadgets.window.adjustHeight('1220');
}, params,0) ;
	        
		break;
			case 'b':
			if(vlang==1)
			{
			document.getElementById('addiv').innerHTML="<img src='http://orkut.familybuilder.com/spanish_images/steps2.gif' align='center'>";
			}
			else
			{
			document.getElementById('addiv').innerHTML="<img src='http://orkut.familybuilder.com/images/header_images/steps2.gif' align='center'>";
			}
			
			url="http://orkut.familybuilder.com/FamilyList.php?"+stringuri;
    
		var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
    makeCachedRequest(url, function(responseText){
	getMyFriends1('1');
    document.getElementById('output').innerHTML=responseText.text;
    gadgets.window.adjustHeight('1220');
}, params,0) ;
        			
			break;
			
			case 'e':
			document.getElementById('addiv').style.display='none';
				createCookie('gu'+profile_id,'g',2);
				url="http://orkut.familybuilder.com/choicefamily.php?"+stringuri;

		var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
    makeCachedRequest(url, function(responseText){
    document.getElementById('output').innerHTML=responseText.text;
    gadgets.window.adjustHeight('1220');
}, params,0) ;
			 break;  
		}
		
}else{
	document.getElementById('addiv').style.display='none';
}


if(tabId=='tl_0_0'){
	if(_args()["up_tid"]){
		var tid = _args()["up_tid"];
		var pid = _args()["up_pid"];
		var relPID = _args()["up_relPID"];
		var rel = _args()["up_rel"];
		var rid = _args()["up_rid"];

		url="http://orkut.familybuilder.com/addPerson.php?profile_id="+tid+"&tid="+tid+"&pid="+pid+"&relPID="+relPID+"&rel="+rel+"&rid="+rid+"&apid="+apid;

			var params = {};


			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
makeCachedRequest(url, function(responseText){
arr=responseText.text.split('#$#');
// alert("arr="+arr);
document.getElementById('output').innerHTML=arr[0];

gadgets.window.adjustHeight('1220');
// alert("000="+arr[0]);
// alert("11="+arr[1]);

validaddform(arr[1]);
//validaddform();
}, params,0) ;
		
		// _IG_FetchContent(url, function(responseText){
			// _gel('output').innerHTML=responseText;
			// gadgets.window.adjustHeight('1150');
		// }, {refreshInterval:0}) ;
	}else if(_args()["up_Link"]){

		var pid_Link= _args()["up_pid"];
		var tid_Link= _args()["up_tree_id"];


		url="http://orkut.familybuilder.com/addtoprofile.php?profile_id="+tid_Link+"&tid="+tid_Link+"&pid="+pid_Link+"&apid="+escape(apid);

		_IG_FetchContent(url, function(responseText){
			_gel('output').innerHTML=responseText;
			gadgets.window.adjustHeight('950');
			
		}, {refreshInterval:0}) ;

	}else if(_args()["up_fins"]){
	
		var flid=_args()["up_fins"];
		url="http://orkut.familybuilder.com/FamilyList.php?"+stringuri;

	var params = {};


			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;


			makeCachedRequest(url, function(responseText){
			getMyFriends1('1');
document.getElementById('output').innerHTML=responseText.text;

gadgets.window.adjustHeight('1220');
}, params,0) ;
	}else{
		if(_args()["up_ins"]){
			var pid=_args()["up_ins"];
			url="http://orkut.familybuilder.com/addActivity.php?"+ gadgets.io.encodeValues({pid: pid,appid:apid,profile_id:profile_id});
			//alert(url);
			var params = {};


			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;


			gadgets.io.makeRequest(url, function(response){

				if(response.errors!='')
				{
					alert("Errors:" + response.errors);
				}
				else
				{
					var txt=response.text;
					 //alert(txt);
					writeActivity(txt);
				}
			}, params) ;

			setTimeout(function() {window.top.location=_args()["parent"]+"/Application.aspx?appId="+apid+"&up_chk=1&up_tab=tl_0_0";},10000);


		}

	_gel('output').innerHTML = "<iframe src='http://orkut.familybuilder.com/checkGender.php?"+stringuri+"' width='815' height='600' frameborder='0' scrolling='auto'></iframe>";
	}

}
if(tabId=='tl_0_1'){
	_gel('output').innerHTML = "<iframe src='http://orkut.familybuilder.com/profilectn.php?"+stringuri+"' width='815px' height='1200px' frameborder='0' scrolling='auto'></iframe>";
}
if(tabId=='tl_0_Srch'){
 srch=document.getElementById('txtsearch').value;


	_gel('output').innerHTML = "<iframe src='http://orkut.familybuilder.com/browseMembers.php?"+stringuri+"&searchtxt="+srch+"' width='815px' height='600px' frameborder='0' scrolling='auto'></iframe>";
}
if(tabId=='tl_0_2'){

	_gel('output').innerHTML = "<iframe src='http://orkut.familybuilder.com/browseMembers.php?"+stringuri+"' width='815px' height='600px' frameborder='0' scrolling='auto'></iframe>";
}
if(tabId=='poll'){

	_gel('output').innerHTML = "<iframe src='http://orkut.familybuilder.com/poll.php?"+stringuri+"' width='815px' height='600px' frameborder='0' scrolling='auto'></iframe>";
}

if(tabId=='tl_0_3'){

	url="http://orkut.familybuilder.com/FamilyList.php?"+stringuri;
    var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
    makeCachedRequest(url, function(responseText){
	getMyFriends1('1');
    document.getElementById('output').innerHTML=responseText.text;
    gadgets.window.adjustHeight('1220');
}, params,0) ;
}
if(tabId=='t_insetup'){
url="http://orkut.familybuilder.com/intialsetup_new.php?"+stringuri;
    var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
    makeCachedRequest(url, function(responseText){
    document.getElementById('output').innerHTML=responseText.text;
    gadgets.window.adjustHeight('1220');
}, params,0) ;

}
if(tabId=='tl_0_chc'){
url="http://orkut.familybuilder.com/choicefamily.php?"+stringuri;
    var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
    makeCachedRequest(url, function(responseText){
    document.getElementById('output').innerHTML=responseText.text;
    gadgets.window.adjustHeight('1220');
}, params,0) ;

}
if(tabId=='tl_0_all'){

url="http://orkut.familybuilder.com/feed.php?"+stringuri;

var params = {};


			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;


			makeCachedRequest(url, function(responseText){
document.getElementById('output').innerHTML=responseText.text;

allFeed(stringuri,1);
gadgets.window.adjustHeight('1150');
}, params,0) ;


}
if(tabId=='tl_0_6'){
	url="http://orkut.familybuilder.com/Home.php?"+stringuri;
var params = {};
			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
		makeCachedRequest(url, function(responseText){
		arr=responseText.text.split('#$#');
		//alert("arr="+arr);
document.getElementById('output').innerHTML=arr[0];
gadgets.window.adjustHeight('1250');
saveData(stringuri);
 //alert("000="+arr[0]);
// alert("11="+arr[1]);
//discussvalid(arr[1]);
discussvalid(arr[1]);
}, params,0) ;
}

if(tabId=='Help'){
	getPage('Help',profile_id);
	gadgets.window.adjustHeight('1150');
}
if(tabId=='About'){
	getPage('About',profile_id);
	gadgets.window.adjustHeight('1150');
}
if(tabId=='Privacy'){
	getPage('Privacy',profile_id);
	gadgets.window.adjustHeight('1150');
}
if(tabId=='Bugs'){
	_gel('output').innerHTML = "<iframe src='http://orkut.familybuilder.com/bugs.php?"+stringuri+"' width='815px' height='600px' frameborder='0' scrolling='true'></iframe>";
	gadgets.window.adjustHeight('1150');
}
if(tabId=='Settings'){
	_gel('output').innerHTML = "<iframe src='http://orkut.familybuilder.com/treeSettings.php?"+stringuri+"' width='815px' height='600px' frameborder='0' scrolling='true'></iframe>";
	gadgets.window.adjustHeight('1150');
}
function getPage(url,user){
debug("getPage");

	if(url=='Help'){
		url="http://orkut.familybuilder.com/help.php?profile_id="+user;
		//alert(url);
	}else if(url=='About'){
		url='http://orkut.familybuilder.com/aboutus.php?profile_id='+user;
		//alert(url);
		
		
	}else if(url=='Privacy'){
		url='http://orkut.familybuilder.com/privacy.php?profile_id='+user;
	}
	var params = {};
	params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
	gadgets.io.makeRequest(url, function(response){
	//alert("here");
	if(response.errors!='')
	{
	alert("Errors:" + response.errors);
	}
	else
	{
	var txt=response.text;
	_gel('output').innerHTML =txt;
	//alert(txt);

	gadgets.window.adjustHeight('1150');
	}
}, params) ;


}



//showname(profile_id,apid);
//showpoints(profile_id,apid);
gadgets.window.adjustHeight('1150');
});
};

arrvalid=new Array();
arrvalid[0]=new Array('Please enter comment','Please enter story','Please enter Name','Please enter location','Please enter address','Please enter gift details','Please enter recipe name','Please enter ingredients','Please enter instructions','Please enter other details');
arrvalid[1]=new Array('Por favor, introduzca comentario','Por favor, introduzca historia','Por favor, introduzca Nombre','Por favor, introduzca la ubicaci&oacute;n','Por favor, introduzca la direcci&oacute;n','Por favor, introduzca los detalles de regalo','Por favor, introduzca nombre de la receta','Por favor, introduzca los ingredientes','Por favor, escriba las instrucciones','Por favor, entrar en otros detalles');

function discussvalid(langV)
{
	debug("discussvalid");
//alert("value="+langV);
langV=parseInt(langV);
// alert(arrvalid[langV][0]);
var f1 = new LiveValidation('Comment');	
f1.add( Validate.Presence,{ failureMessage: arrvalid[langV][0]});

var f2 = new LiveValidation('story');	
f2.add( Validate.Presence,{ failureMessage: arrvalid[langV][1]});

var f3 = new LiveValidation('Name');	
f3.add( Validate.Presence,{ failureMessage: arrvalid[langV][2]});

var f4 = new LiveValidation('loc');	
f4.add( Validate.Presence,{ failureMessage: arrvalid[langV][3]});

var f5 = new LiveValidation('address');	
f5.add( Validate.Presence,{ failureMessage: arrvalid[langV][4]});


var f6 = new LiveValidation('answer');	
f6.add( Validate.Presence,{ failureMessage: arrvalid[langV][5]});

var f7 = new LiveValidation('Recipe_Name');	
f7.add( Validate.Presence,{ failureMessage: arrvalid[langV][6]});


var f8 = new LiveValidation('Ingredients');	
f8.add( Validate.Presence,{ failureMessage: arrvalid[langV][7]});

var f9 = new LiveValidation('Instructions');	
f9.add( Validate.Presence,{ failureMessage: arrvalid[langV][8]});

var f10 = new LiveValidation('What5');	
f10.add( Validate.Presence,{ failureMessage: arrvalid[langV][9]});

}


function getProfile(){
debug("getProfile");

var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');
req.send(function(data){
person = data.get('viewer');
person = person.getData() || {};
var profile_id=person.getId();
_gel('tablout1').style.display="none";
var url= "http://orkut.familybuilder.com/profile.php?profile_id="+profile_id+"&apid="+escape(apid);
_IG_FetchContent(url, function(responseText){

_gel('tablout').innerHTML=responseText;
_IG_AdjustIFrameHeight();
}) ;

});
}



/**
* Request friend data and specify the "gotFriends" callback
*/

gadgets.util.registerOnLoadHandler(function() {

var isAble = 1;
var myenv = opensocial.getEnvironment();


views = gadgets.views.getSupportedViews();
currentview = gadgets.views.getCurrentView();

var surf = currentview;

if(surf.getName()=="canvas"){
//if(_args()["up_chk"])
//{

if(_args()["up_tab"]){
var tab=_args()["up_tab"];
chngTab(tab);
doRequest(tab);
}else{
doRequest('tl_0_3');
}

gadgets.window.adjustHeight('1150');

//}
//else
//{

//var apid ='87222226184';// opensocial.Activity.getField('APP_ID');


//window.top.location=_args()["parent"]+"/Application.aspx?appId="+apid+"&up_chk=1";

//}
}else{

getProfile();
}
});

function chkFrame(id){
alert(id);
}

function show(id){
	debug("show");
	
		for(i=1;i<=7;i++){
		document.getElementById('div_'+i).style.display='none';
		}
	document.getElementById('div_'+id).style.display='block';

	}
function hide(id){
		debug("hide");
		
	document.getElementById('div_'+id).style.display='none';

	}
function initCall(){
	debug("initCall");
	
//alert('initcall');
/**
* Request friend data and specify the "gotFriends" callback
*/

gadgets.util.registerOnLoadHandler(function() {

var isAble = 1;
var myenv = opensocial.getEnvironment();


views = gadgets.views.getSupportedViews();
currentview = gadgets.views.getCurrentView();

var surf = currentview;

if(surf.getName()=="canvas"){
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');
req.send(function(data){
person = data.get('viewer');
person = person.getData() || {};
var profile_id=person.getId();
url="http://orkut.familybuilder.com/header.php?profile_id="+profile_id;

		var params = {};
		params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
		makeCachedRequest(url, function(responseText){
		//alert(responseText.text);
			_gel('tablout').innerHTML=responseText.text;
			for(i=1;i<=7;i++){
		document.getElementById('div_'+i).style.display='none';
		}
			
		var cookvar=document.getElementById('cookvar').value;
        var vlang=document.getElementById('langV').value;
if(_args()["up_cook"]){

createCookie('gu'+profile_id,'a',2);
}
if(cookvar==0){	
createCookie('gu'+profile_id,'a',2);
}
var ck=readCookie('gu'+profile_id);	
// alert(ck);
// alert(vlang);
if(ck && ck!="" && ck!="g")
{

		switch (ck){
			case 'a':
			if(vlang==0)
			{
			document.getElementById('addiv').innerHTML="<img src='http://orkut.familybuilder.com/images/header_images/steps1.gif' align='center'>";
			}
			else
			{
			document.getElementById('addiv').innerHTML="<img src='http://orkut.familybuilder.com/spanish_images/steps1.gif' align='center'>";
			}
			doRequest('t_insetup');
			  break;
			case 'b':
			if(vlang==1)
			{
			document.getElementById('addiv').innerHTML="<img src='http://orkut.familybuilder.com/spanish_images/steps2.gif' align='center'>";
			}
			else
			{
			document.getElementById('addiv').innerHTML="<img src='http://orkut.familybuilder.com/images/header_images/steps2.gif' align='center'>";
			}
			doRequest('tl_0_3');
			break;
			case 'e':
				createCookie('gu'+profile_id,'g',2);				
				doRequest('tl_0_chc');
			break;
		}
}		
else
{	
		
if(_args()["up_tab"]){
var tab=_args()["up_tab"];
chngTab(tab);

doRequest(tab);

}else if(_args()["up_userLink"]){
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');
req.send(function(data){
person = data.get('viewer');
person = person.getData() || {};
var profile_id=person.getId();
window.top.location='http://www.familybuilder.com/familytree/Linktree.php?userID='+profile_id+'&userLinkId='+_args()["up_userLink"]+'&confirm=Orkut';
});
}else{
doRequest('tl_0_3');
}
}
gadgets.window.adjustHeight('1150');
}, params,0) ;
});
}else{

getProfile();
}
});


}

function comingsoon(user)
{
	debug("comingsoon");
url="http://orkut.familybuilder.com/comingsoon.php?profile_id="+user;

var params = {};
			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;

			makeCachedRequest(url, function(responseText){
			try {
			popupWindow('popup1',true);
            document.getElementById("popup1").innerHTML=responseText.text;
					} catch(e) {}
		

			},params,0) ;


}

function showdlogname(typ)
{
	debug("showdlogname");
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');

req.send(function(data){

var profile_id=person.getId();
if(typ=="points"){
url="http://orkut.familybuilder.com/pointsdlog.php?profile_id="+profile_id+"&apid="+apid;
}
else
{
url="http://orkut.familybuilder.com/shownamedialog.php?profile_id="+profile_id+"&apid="+apid;
}

var params = {};


			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;


			makeCachedRequest(url, function(responseText){
		popupWindow('popup1',true);
        document.getElementById("popup1").innerHTML=responseText.text;

			},params,0) ;

});
}
function submitupdate()
{
	debug("submitupdate");
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');

req.send(function(data){

var profile_id=person.getId();
var name=document.getElementById('txtName23').value;
var name1=document.getElementById('txtName24').value;
var gender=document.getElementById('rdgen').value;
var mail=document.getElementById('txtName25').value;
url="http://orkut.familybuilder.com/updateuser.php?name="+name+"&lname="+name1+"&gender="+gender+"&mail="+mail+"&apid="+apid+"&profile_id="+profile_id;

var params = {};
	params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
    	makeCachedRequest(url, function(responseText){
		popupWindow('popup1',true);
        document.getElementById('name').innerHTML=responseText.text;
        document.getElementById("shwedt").innerHTML=responseText.text;
        document.getElementById('popup1').style.display='none';

			},params,0) ;
			});
}

function showname(user,apid){
	debug("showname");
	
url="http://orkut.familybuilder.com/getname.php?profile_id="+user+"&apid="+apid;
    var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
    makeCachedRequest(url, function(responseText){
	document.getElementById('name').innerHTML=responseText.text;
}, params,0);
}
function opentree(){
	debug("opentree");
window.top.location=_args()["parent"]+"/Application.aspx?appId="+apid+"&up_chk=1&up_tab=tl_0_0";
}
function openfamilylist(){
	debug("openfamilylist");
			window.top.location=_args()["parent"]+"/Application.aspx?appId="+apid+"&up_chk=1&up_tab=tl_0_3";
}

function updateintial(cko)
{
	debug("updateintial");
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');

req.send(function(data){
var profile_id=person.getId();
var name=document.getElementById('txtName23').value;
var name1=document.getElementById('txtName24').value;
var mail=document.getElementById('txtName25').value;
var gender=document.getElementById('rdgen').value;
var dt=document.getElementById('dt').value;
var month=document.getElementById('month').value;
var year=document.getElementById('year').value;
var lng=document.getElementById('lng').value;

url="http://orkut.familybuilder.com/updateintials.php?name="+name+"&lname="+name1+"&gender="+gender+"&mail="+mail+"&apid="+apid+"&profile_id="+profile_id+"&dt="+dt+"&month="+month+"&year="+year+"&lng="+lng;

var params = {};
	params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
    	makeCachedRequest(url, function(responseText){
		createCookie(cko,'b',2);
        window.top.location=_args()["parent"]+"/Application.aspx?appId="+apid+"&up_chk=1&up_tab=tl_0_3";
		        
			},params,0) ;
			});

}
function languagesave(lval)
{
	debug("languagesave");
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');

req.send(function(data){
var profile_id=person.getId();
url="http://orkut.familybuilder.com/languagesave.php?lval="+lval+"&profile_id="+profile_id;

var params = {};
	params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
    	makeCachedRequest(url, function(responseText){
		window.top.location=_args()["parent"]+"/Application.aspx?appId="+apid+"&up_chk=1&up_tab=tl_0_3";
		//doRequest('t_insetup');
			},params,0) ;
			});

}

function chkcookie(name,tabid){
	debug("chkcookie");
			ck=readCookie(name);
			if(tabid=='tl_0_0' && ck!="g"){
			createCookie(name,'e',2);
			window.top.location=_args()["parent"]+"/Application.aspx?appId="+apid+"&up_chk=1&up_tab=tl_0_0";
			}
}
function createCookie(name,value,days) {
	debug("createCookie");
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


function readCookie(name) {
	debug("readCookie");

	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		
		if (c.indexOf(nameEQ) == 0) 
		//document.getElementById('ckdiv').innerHTML=c.substring(nameEQ.length,c.length);
		return c.substring(nameEQ.length,c.length);
	}
	return null;
}



function showpoints(user,apid){
		debug("showpoints");	
	
		url="http://orkut.familybuilder.com/getpoints.php?profile_id="+user+"&apid="+apid;
	//alert(url);
			var params = {};


			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
            makeCachedRequest(url, function(responseText){
		document.getElementById('pointsvalue').innerHTML=responseText.text;
        //document.getElementById('loader').style.display = 'none';

			},params,0) ;


}

function getpointsDetail(){
	debug("getpointsDetail");
	
	var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');

req.send(function(data){

var profile_id=person.getId();
url="http://orkut.familybuilder.com/totalpoints.php?profile_id="+profile_id+"&apid="+apid;
		
	var params = {};


			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;


			makeCachedRequest(url, function(responseText){
		popupWindow('popup1',true);
        document.getElementById("popup1").innerHTML=responseText.text;

			},params,0) ;

});

}


arrform=new Array();
arrform[0]=new Array('Please enter first name','Only standard characters are allowed','Please use the format dd-mmm-yyyy','Enter a valid email address');
arrform[1]=new Array('Por favor, introduzca el nombre','Solo caracteres estandar se permite','Por favor, utilice el formato dd-mmm-aaaa','Introduzca una direccion de correo electronico valida');

function validaddform(lang)
{
	debug("validaddform");
//alert("value="+lang);
lang=parseInt(lang);
// alert(arrvalid[langV][0]);
var f1 = new LiveValidation('fname');	
f1.add( Validate.Presence,{ failureMessage: arrform[lang][0]} ).add(Validate.Format, {pattern: /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/i , failureMessage: arrform[lang][1]});



var f2 = new LiveValidation('lname');	
f2.add(Validate.Format, {pattern: /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/i , failureMessage: arrform[lang][1]});

var f3 = new LiveValidation('bplace');	
f3.add(Validate.Format, {pattern: /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/i , failureMessage: arrform[lang][1]});

var f4 = new LiveValidation('bdate');	
f4.add(Validate.Format, {pattern: /^\d{1,2}\-(([A-Za-z]{1,3}))\-((\d{4}))$/i  , failureMessage: arrform[lang][2]});

var f5 = new LiveValidation('dplace');	
f5.add(Validate.Format, {pattern: /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/i , failureMessage:arrform[lang][1]});

var f6 = new LiveValidation('ddate');	
f6.add(Validate.Format, {pattern: /^\d{1,2}\-(([A-Za-z]{1,3}))\-((\d{4}))$/i  , failureMessage: arrform[lang][2]});

var f7 = new LiveValidation('email');
f7.add( Validate.Email , {failureMessage: arrform[lang][3]});

}
